#include "beetxcore.h"
#include "CalendarTrans.h"

jstring Java_com_xiaofengwx_remind_BeetxJni_test(JNIEnv* env, jobject thiz) {
	return env->NewStringUTF("Hello from JNI!~~");
}

jboolean Java_com_xiaofengwx_remind_BeetxJni_DateTimeToChineseL(JNIEnv* env,
		jobject thiz, jintArray aDateTime, jintArray aChineseDate) {

	int *arrDateTime = env->GetIntArrayElements(aDateTime, 0);
	int *arrChineseDate = env->GetIntArrayElements(aChineseDate, 0);
	MyDate aMyDate;
	aMyDate.init(arrDateTime);

	MyChineseDate aMyChineseDate;
	MyChineseCalendarConverter::DateTimeToChineseL(aMyDate, aMyChineseDate);
	aMyChineseDate.export_(arrChineseDate);

	env->ReleaseIntArrayElements(aDateTime, arrDateTime, 0);
	env->ReleaseIntArrayElements(aChineseDate, arrChineseDate, 0);
}

jboolean Java_com_xiaofengwx_remind_BeetxJni_ChineseToDateTimeL(JNIEnv* env,
		jobject thiz, jintArray aChineseDate, jintArray aDateTime) {

	int *arrDateTime = env->GetIntArrayElements(aDateTime, 0);
	int *arrChineseDate = env->GetIntArrayElements(aChineseDate, 0);
	MyChineseDate aMyChineseDate;
	aMyChineseDate.init(arrChineseDate);

	MyDate aMyDate;
	MyChineseCalendarConverter::ChineseToDateTimeL(aMyChineseDate, aMyDate);
	aMyDate.export_(arrDateTime);

	env->ReleaseIntArrayElements(aDateTime, arrDateTime, 0);
	env->ReleaseIntArrayElements(aChineseDate, arrChineseDate, 0);
}

void Java_com_xiaofengwx_remind_BeetxJni_DateRangeG(JNIEnv* env, jobject thiz,
		jintArray aDateTime, jintArray bDateTime) {

	int *arrDateTimeA = env->GetIntArrayElements(aDateTime, 0);
	int *arrDateTimeB = env->GetIntArrayElements(bDateTime, 0);

	MyDate aMyDate, bMyDate;
	MyChineseCalendarConverter::DateRange(aMyDate, bMyDate);
	aMyDate.export_(arrDateTimeA);
	bMyDate.export_(arrDateTimeB);

	env->ReleaseIntArrayElements(aDateTime, arrDateTimeA, 0);
	env->ReleaseIntArrayElements(bDateTime, arrDateTimeB, 0);
}

void Java_com_xiaofengwx_remind_BeetxJni_DateRangeN(JNIEnv* env, jobject thiz,
		jintArray aChineseDate, jintArray bChineseDate) {
	int *arrChineseDateA = env->GetIntArrayElements(aChineseDate, 0);
	int *arrChineseDateB = env->GetIntArrayElements(bChineseDate, 0);

	MyChineseDate aMyChineseDate, bMyChineseDate;
	MyChineseCalendarConverter::DateRange(aMyChineseDate, bMyChineseDate);
	aMyChineseDate.export_(arrChineseDateA);
	bMyChineseDate.export_(arrChineseDateB);

	env->ReleaseIntArrayElements(aChineseDate, arrChineseDateA, 0);
	env->ReleaseIntArrayElements(bChineseDate, arrChineseDateB, 0);
}
